import  tkinter as tk

def sort():
    numbers = [int(x) for x in array_entry.get().split(',')]

    for i in range((len(numbers) - 1) // 2):
        for j in range(len(numbers) - i - 2):
            if numbers[j] > numbers[j + 2]:
                numbers[j], numbers[j + 2] = numbers[j + 2], numbers[j]

    for i in range(len(numbers) // 2):
        j = 2 * i
        if numbers[j] > numbers[j + 1]:
            numbers[j], numbers[j + 1] = numbers[j + 1], numbers[j]

    for i in range(2, len(numbers)-1, 2):
        t = numbers[i]
        j = i - 1
        while t < numbers[j]:
            numbers[j + 1] = numbers[j]
            j -= 1
        numbers[j + 1] = t

    result.set(','.join(map(str, numbers)))

win=tk.Tk()
win.title('排序')
win.resizable(0, 0)
result=tk.StringVar('')
input_label =tk.Label(win, text='输入待排序数据：')
input_label.grid(row=0, column=0)
array_entry =tk.Entry(win)
array_entry.grid(row=0, column=1)
output_label =tk.Label(win, text='排序后的数据为')
output_label.grid(row=1, column=0)
result_entry =tk.Label(win,textvariable=result)
result_entry.grid(row=1, column=1)
convert_button =tk.Button(win, text='排序', command=sort)
convert_button.grid(row=2, column=1)

win.mainloop()
